local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, script.Parent.base,script.Parent.Name);
local ConnectClass=_G.CommonOHOH.load.Connect();
local ColliderGroup = CommonOHOH.load.ColliderGroup();
local ColliderManager = CommonOHOH.load.ColliderManager();
-- local monster_cfg = CommonOHOH.config.Monster

local MonsterTool=CommonOHOH.load.MonsterTool()
local HttpService = game:GetService("HttpService")
local attackCd=_G.CommonOHOH.config.Game.monster_attack_cd--攻击CD

function M.new(...)
	return M(...);
end;

-- function M.ctor(self,guid,obj,battle,cfgId,hp,maxHp,damge,attackCd,drop,walkSpeed)

function M.ctor(self,levelId,cid,battle,startCF,...)
    local cfg=MonsterTool.GetCfgByLvIdAndCid(levelId,cid)
    local obj= MonsterTool.GetMonsterPerfabByMId(cfg.id)
    local guid=HttpService:GenerateGUID(false)
    obj.Name=guid
    local att=battle:GetPrivateComponent("AttCtrl")
    obj.Parent=att:FindMonsterFolder()

    M.super.ctor(self,obj,battle,...)
    self.cfg=cfg

    --初始化网络属性
    self:InitNetAttribute(levelId,cid,cfg.id,cfg.hp,cfg.hp,cfg.attack,attackCd)

    -- 初始化一般属性
    self:InitAttribute(cfg.drop,cfg.walkSpeed)

    --初始化位置
    self:SetCFrame(startCF)

    --设置碰撞组
    ColliderManager:SetAllGroup(self.main_inst, ColliderGroup.monster);

    --添加服务器端控制器
    self:AddPrivateComponentByFolder(script.Parent.ser)




    self.DieEvent:Connect(function()
        self.Battle:AddKilledCount(1)
    end)

end;

-- 开始行动攻击玩家
function M.Action(self)
    --进入追击状态
    self:ActiveAttack()
    self.ChaseTargetEvent:Action()

    -- self:SwitchState("follow") --追寻玩家
end

function M.dtor(self)
    local obj=self.main_inst
    -- self.main_inst:Destroy()
	M.super.dtor(self);
    obj:Destroy()
    --print("怪物被销毁---》",self.Guid)
end;


function M.GoToDead(self)
    --print("怪物被死亡---》",self.Guid)
    self:Dead()
end


-- -- 由服务器决定怪物是否死亡
-- function M.Hurt(self,damge,attacker)

--     M.super.Hurt(self,damge,attacker);
--     -- if self.attribute.Hp==0 then
--     --     self:Dead(attacker)
--     --     self.Battle:AddKilledCount(1)
--     -- end
-- end


return M
